//
//  SignUpView.m
//  NoNeedle
//
//  Created by Ming Tian on 2017/3/8.
//  Copyright © 2017年 Ming Tian. All rights reserved.
//

#import "SignUpView.h"

const double signupButtonRate = 90.0f/450.0f;

@implementation SignUpView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.usernameLeftImageView = [[UIImageView alloc]init];
    self.usernameLeftImageView.image = [UIImage imageNamed:@"icon_login_user"];
    [self addSubview:self.usernameLeftImageView];
    
    self.usernameTextField = [[UITextField alloc]init];
    self.usernameTextField.font = [UIFont systemFontOfSize:15];
    self.usernameTextField.placeholder = @"手机号";
    self.usernameTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.usernameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:self.usernameTextField];
    
    self.verifyLeftImageView = [[UIImageView alloc]init];
    self.verifyLeftImageView.image = [UIImage imageNamed:@"icon_login_vc"];
    [self addSubview:self.verifyLeftImageView];
    
    self.verifyTextField = [[UITextField alloc]init];
    self.verifyTextField.font = [UIFont systemFontOfSize:15];
    self.verifyTextField.placeholder = @"验证码";
    self.verifyTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self addSubview:self.verifyTextField];
    
    self.verifyButton = [[UIButton alloc]init];
    [self.verifyButton setTitleColor:NavBackColor forState:UIControlStateNormal];
    [self.verifyButton setTitle:@"获取" forState:UIControlStateNormal];
    self.verifyButton.layer.borderColor = NavBackColor.CGColor;
    self.verifyButton.layer.borderWidth = 1;
    self.verifyButton.layer.cornerRadius = 13;
    [self addSubview:self.verifyButton];
    
    self.passwordLeftImageView = [[UIImageView alloc]init];
    self.passwordLeftImageView.image = [UIImage imageNamed:@"icon_login_passworld"];
    [self addSubview:self.passwordLeftImageView];
    
    self.passwordTextField = [[UITextField alloc]init];
    self.passwordTextField.font = [UIFont systemFontOfSize:15];
    self.passwordTextField.placeholder = @"密码";
    self.passwordTextField.secureTextEntry = YES;
    self.passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:self.passwordTextField];

    self.confirmPasswordLeftImageView = [[UIImageView alloc]init];
    self.confirmPasswordLeftImageView.image = [UIImage imageNamed:@"icon_login_passworld"];
    [self addSubview:self.confirmPasswordLeftImageView];
    
    self.confirmPasswordTextField = [[UITextField alloc]init];
    self.confirmPasswordTextField.font = [UIFont systemFontOfSize:15];
    self.confirmPasswordTextField.placeholder = @"确认密码";
    self.confirmPasswordTextField.secureTextEntry = YES;
    self.confirmPasswordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:self.confirmPasswordTextField];
    
    self.addressLeftImageView = [[UIImageView alloc]init];
    self.addressLeftImageView.image = [UIImage imageNamed:@"icon_login_user"];
    [self addSubview:self.addressLeftImageView];
    
    self.addressTextField= [[UITextField alloc]init];
    self.addressTextField.font = [UIFont systemFontOfSize:15];
    self.addressTextField.placeholder = @"推荐人手机";
    self.addressTextField.enabled = YES;
    self.addressTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.addressTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:self.addressTextField];
    
//    self.addressChoose =  [UIButton buttonWithType:UIButtonTypeCustom] ;
//    self.addressChoose.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
//    [self.addressChoose setImage:[UIImage imageNamed:@"icon_title_more"] forState:UIControlStateNormal];
//    
//    [self addSubview:self.addressChoose];
    
    self.checkboxButton = [[UIButton alloc]init];
    [self.checkboxButton setImage:[UIImage imageNamed:@"icon_login_check_pre"] forState:UIControlStateNormal];
    [self.checkboxButton setImage:[UIImage imageNamed:@"icon_login_check"] forState:UIControlStateSelected];
    [self addSubview:self.checkboxButton];
    
    self.hintTextView = [[UITextView alloc]init];
    self.hintTextView.backgroundColor = [UIColor clearColor];
    self.hintTextView.scrollEnabled = NO;
    self.hintTextView.selectable = YES;
    self.hintTextView.editable = NO;
    [self addSubview:self.hintTextView];
    NSMutableAttributedString *hintStr = [[NSMutableAttributedString alloc]initWithString:@"注册代表同意用户协议"];
    [hintStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, hintStr.length)];
    [hintStr addAttribute:NSLinkAttributeName value:@"用户协议" range:NSMakeRange(6, 4)];
    [hintStr addAttribute:NSForegroundColorAttributeName value:RGBa(0x999999) range:NSMakeRange(0, 6)];
    [hintStr addAttribute:NSForegroundColorAttributeName value:RGBa(0x08d66d) range:NSMakeRange(6, 4)];
    self.hintTextView.attributedText = hintStr;
    
    self.signupButton = [[UIButton alloc]init];
    self.signupButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.signupButton setTitle:@"确认注册" forState:UIControlStateNormal];
    [self.signupButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    self.signupButton.backgroundColor = NavBackColor;
    self.signupButton.layer.cornerRadius = screenW*0.65*signupButtonRate/2;
    self.signupButton.layer.masksToBounds = NO;
    [self.signupButton setBackgroundImage:ImageName(@"icon_login__buttton_bg") forState:UIControlStateNormal];
    [self addSubview:self.signupButton];
    // 按钮投影
//    self.signupButton.layer.shadowColor = NavBackColor.CGColor;
//    self.signupButton.layer.shadowOpacity = 0.6f;
//    self.signupButton.layer.shadowOffset = CGSizeMake(0,2);
//    self.signupButton.layer.shadowRadius = 4;
    
    // 分割线
    self.sepLine1 = [[UIView alloc]init];
    self.sepLine1.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine1];
    self.sepLine2 = [[UIView alloc]init];
    self.sepLine2.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine2];
    self.sepLine3 = [[UIView alloc]init];
    self.sepLine3.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine3];
    self.sepLine4 = [[UIView alloc]init];
    self.sepLine4.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine4];
    self.sepLine5 = [[UIView alloc]init];
    self.sepLine5.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine5];
    
    [self setupConstraints];
}

- (void)setupConstraints {
    [self.sepLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(55);
        make.centerX.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.75);
        make.height.mas_equalTo(1);
    }];
    [self.usernameLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.sepLine1).offset(10);
        make.bottom.equalTo(self.sepLine1).offset(-7);
        make.width.height.mas_equalTo(30);
    }];
    [self.usernameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.usernameLeftImageView.mas_right).offset(10);
        make.bottom.equalTo(self.usernameLeftImageView);
        make.right.equalTo(self.sepLine1);
        make.height.equalTo(self.usernameLeftImageView);
    }];
    [self.verifyLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sepLine1).offset(7);
        make.left.equalTo(self.usernameLeftImageView);
        make.width.equalTo(self.usernameLeftImageView);
        make.height.equalTo(self.usernameLeftImageView);
    }];
    [self.verifyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.verifyLeftImageView);
        make.left.equalTo(self.usernameTextField);
        make.right.equalTo(self.usernameTextField).offset(-60);
        make.height.equalTo(self.usernameTextField);
    }];
    [self.verifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.verifyTextField);
        make.left.equalTo(self.verifyTextField.mas_right);
        make.right.equalTo(self.usernameTextField);
        make.height.equalTo(self.verifyTextField).offset(-4);
    }];
    [self.sepLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.verifyLeftImageView.mas_bottom).offset(7);
        make.centerX.equalTo(self);
        make.width.equalTo(self.sepLine1);
        make.height.equalTo(self.sepLine1);
    }];
    [self.passwordLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sepLine2).offset(7);
        make.left.equalTo(self.verifyLeftImageView);
        make.width.equalTo(self.verifyLeftImageView);
        make.height.equalTo(self.verifyLeftImageView);
    }];
    [self.passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passwordLeftImageView);
        make.left.equalTo(self.verifyTextField);
        make.right.equalTo(self.sepLine2);
        make.height.equalTo(self.verifyTextField);
    }];
    [self.sepLine3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passwordLeftImageView.mas_bottom).offset(7);
        make.centerX.equalTo(self);
        make.width.equalTo(self.sepLine2);
        make.height.equalTo(self.sepLine2);
    }];
    [self.confirmPasswordLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sepLine3).offset(7);
        make.left.equalTo(self.passwordLeftImageView);
        make.width.equalTo(self.passwordLeftImageView);
        make.height.equalTo(self.passwordLeftImageView);
    }];
    [self.confirmPasswordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.confirmPasswordLeftImageView);
        make.left.equalTo(self.passwordTextField);
        make.right.equalTo(self.passwordTextField);
        make.height.equalTo(self.passwordTextField);
    }];
    [self.sepLine4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.confirmPasswordLeftImageView.mas_bottom).offset(7);
        make.centerX.equalTo(self);
        make.width.equalTo(self.sepLine3);
        make.height.equalTo(self.sepLine3);
    }];
    [self.addressLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sepLine4).offset(7);
        make.left.equalTo(self.confirmPasswordLeftImageView);
        make.width.equalTo(self.confirmPasswordLeftImageView);
        make.height.equalTo(self.confirmPasswordLeftImageView);
    }];
    [self.addressTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressLeftImageView);
        make.left.equalTo(self.confirmPasswordTextField);
        make.right.equalTo(self.confirmPasswordTextField);
        make.height.equalTo(self.confirmPasswordTextField);
    }];
//    [self.addressChoose mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.addressTextField.mas_top).offset(-7);
//        make.left.equalTo(self.addressLeftImageView.mas_left);
//        make.right.equalTo(self.addressTextField);
//        make.bottom.equalTo(self.addressTextField).offset(7);
//    }];
    [self.sepLine5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressTextField.mas_bottom).offset(7);
        make.centerX.equalTo(self);
        make.width.equalTo(self.sepLine4);
        make.height.equalTo(self.sepLine4);
    }];
    [self.hintTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressLeftImageView.mas_bottom).offset(10);
        make.centerX.equalTo(self).offset(13);
        make.width.mas_equalTo(180);
        make.height.mas_equalTo(25);
    }];
    [self.checkboxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.hintTextView).offset(5);
        make.right.equalTo(self.hintTextView.mas_left);
        make.height.equalTo(self.hintTextView);
        make.width.equalTo(self.checkboxButton.mas_height).multipliedBy(1);
    }];
    [self.signupButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.hintTextView.mas_bottom).offset(20);
        make.width.equalTo(self).multipliedBy(0.65);
        make.height.mas_equalTo(80);
    }];
}

@end
